package mysql

import "gorm.io/gorm"

type Patient struct {
	gorm.Model
	DoctorId       int    `gorm:"type:int(10);not null;comment:'医生id'"`
	BedNumber      string `gorm:"type:varchar(50);not null;comment:'病床号'"`
	PatientName    string `gorm:"type:varchar(10);not null;comment:'患者名称'"`
	PatientAge     int    `gorm:"type:int(10);not null;comment:'年龄'"`
	PatientGender  int    `gorm:"type:int(10);not null;comment:'性别: 1:男 2:女'"`
	Diagnosis      string `gorm:"type:varchar(100);not null;comment:'诊断'"`
	ChronicDisease string `gorm:"type:varchar(100);not null;comment:'慢性病'"`
	AllerGen       string `gorm:"type:varchar(100);not null;comment:'过敏源'"`
	Status         int    `gorm:"type:int(11);not null;comment:'状态: 1:在院 2:出院 3:归档 '"`
}

func GetPatientList(doctorId int64, status int) (result []*Patient, err2 error) {
	if status == 0 {
		DB.Debug().Where("doctor_id = ?", doctorId).Find(&result)
	} else {
		err2 = DB.Debug().Where("status = ?", status).Where("doctor_id = ?", doctorId).Find(&result).Error
		if err2 != nil {
			return nil, err2
		}
	}
	return
}

func GetPatientShow(id int64) (result *Patient, err2 error) {
	err2 = DB.Debug().Where("id = ?", id).Limit(1).Find(&result).Error
	if err2 != nil {
		return nil, err2
	}
	return
}
